package com.yjd.pub.merchant.service;

import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.funds.enums.FundsIncomeEnum;
import com.yjd.comm.merchant.enums.MerchantFundRefTabEnum;
import com.yjd.comm.merchant.enums.MerchantFundsTypeEnum;
import com.yjd.comm.merchant.model.MerchantFundsDataModel;
import com.yjd.comm.merchant.service.IMerchantFundsDataService;
import com.yjd.pub.merchant.dao.IMerchantFundsDataDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <b>description</b>：商户资金流水表业务实现<br>
 * <b>time</b>：2017-10-19 15:50:08 <br>
 * <b>author</b>：  carl
 */
@Service("merchantFundsDataService")
public class MerchantFundsDataServiceImpl extends BaseServiceImpl implements IMerchantFundsDataService {

	/**
	 * 插入
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public MerchantFundsDataModel insert(MerchantFundsDataModel model) throws Exception {
		return this.merchantFundsDataDao.insertModel(model, true);
	}

	/**
	 * 更新
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public int update(MerchantFundsDataModel model) throws Exception {
		return this.merchantFundsDataDao.updateModel(model, true);
	}

	/**
	 * 根据id删除
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(long id) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("id", id);
		return this.merchantFundsDataDao.deleteModel(paramMap, true);
	}


	/**
	 * 新增商户资金流水
	 * @param org_id
	 * @param price
	 * @param balance
	 * @param incomeEnum
	 * @param typeEnum
	 * @param ref_id
	 * @param refTableEnum
	 * @param currtime
	 * @throws Exception
	 */
	@Override
	public void insertFundsData(Long org_id, Double price, Double balance, FundsIncomeEnum incomeEnum, MerchantFundsTypeEnum typeEnum,
								String ref_id, MerchantFundRefTabEnum refTableEnum, Long currtime) throws Exception {
		MerchantFundsDataModel model = new MerchantFundsDataModel();
		model.setOrg_id(org_id);
		model.setPrice(price);
		model.setBalance(balance);
		model.setIncome(incomeEnum.getCode());
		model.setType(typeEnum.getCode());
		model.setRef_id(ref_id);
		model.setRef_table(refTableEnum.getCode());
		model.setUpdate_time(currtime);
		merchantFundsDataDao.insertModel(model,true);
	}

	@Resource
	private IMerchantFundsDataDao merchantFundsDataDao;

	@Override
	public IBaseDao getBaseDao() {
		return this.merchantFundsDataDao;
	}

}
